<script setup lang="ts">
import { categoryStore } from '@/stores/modules/category'
import type { CategoryItems } from '@/types/category'

const categoryStores = categoryStore()

// 定义 props 接收数据
defineProps<{
  list: CategoryItems[]
}>()

const gatoGoods = (goodsId: any) => {
  // 使用 uni.setStorageSync 存储 goodsId
  uni.setStorageSync('activeCategoryId', goodsId);

  // 跳转到目录页
  uni.switchTab({
    url: '/pages/category/category'
  });
}
</script>

<template>
  <view class="category">
    <view
      class="category-item"
      hover-class="none"
      v-for="item in list"
      :key="item.id"
      @tap="gatoGoods(item.id)"
    >
      <text class="iconfont icon" :class="item.url" :style="{ color: item.color }"></text>
      <text class="text">{{ item.name }}</text>
    </view>
  </view>
</template>

<style lang="scss">
@import '../styles/category.scss';
</style>
